//
//  NSAttributedString+Extension.swift
//  WeiBo
//
//  Created by Apple on 16/9/11.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

extension NSAttributedString {
    //  根据表情模型和字体大小创建表情富文本对象
    static func attributedStringWithEmoticon(emoticon: CZEmoticon, font: UIFont) -> NSAttributedString {
        //  1. 创建image对象(通过图片路径创建对象)
        let image = UIImage(named: emoticon.path!)
        //  2. 通过image对象创建文本附件
        let attachment = CZTextAttachment()
        attachment.image = image
        //  设置模型
        attachment.emoticon = emoticon
        //  设置大小
        let fontHeight = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -3, width: fontHeight, height: fontHeight)
        //  3. 通过文本附件创建富文本
        let attributedStr = NSAttributedString(attachment: attachment)
        return attributedStr
    }
    
}
